#include <icecode/test/Test.hpp>
#include "../config.hpp"
#include <string>
#include <stdexcept>

using namespace icecode;

class CFGTest : public test::Test
{
public:
  CFGTest() : test::Test("Configuration class test...") {}

  void run()
  {
    try {
      config::Configuration cfg("test.cfg"), cfg2;

      assert(cfg["variable1"] == "foo", "[] operator 1");
      assert(cfg["variable2"] == "bar", "[] operator 2");
      assert(cfg["variable3"] == "none", "[] operator 3");
      assert(cfg["variable4"] == "", "[] operator 4");

      cfg["variable5"] = "hello world";
      assert(cfg["variable5"] == "hello world", "New variable creation");
      cfg["variable5"] = "hi world";
      assert(cfg["variable5"] == "hi world", "Variable editing");

      except_catch(config::Configuration cfg3("non-existing-config-file.conf"), std::invalid_argument, "Load exception");
      except_catch(cfg2.save(), std::invalid_argument, "Save exception");

      assert(cfg.save("test2.cfg"), "Configuration::save()");
    }
    catch(std::exception e)
      {
	std::cout << e.what() << std::endl;
      }
  }
};

int main()
{
  CFGTest t;
  t.start();
}
